<template>
  <div class="cinema_body">
    <loading v-if="isLoading"></loading>
    <scroll>
      <ul>
        <li v-for="item in cinemas" :key="item.id">
          <div>
            <span>{{item.nm}}</span>
            <span class="q"><span class="price">{{item.sellPrice}}</span> 元起</span>
          </div>
          <div class="address">
            <span>{{item.addr}}</span>
            <span>{{item.distance}}</span>
          </div>
          <div class="card">
            <div v-for="(v,key) in item.tag" :key="key" :class="key | formatCard(['bl','bl','or','or'])" v-if="v===1">{{key | formatCard(['退款','宣传','折扣卡','小吃'])}}</div>
          </div>
        </li>
      </ul>
    </scroll>
  </div>
</template>

<script>
export default {
  data() {
    return {
      cinemas: [],
      isLoading: true,
      prevCity: -1
    }
  },
 methods: {
    async fetch() {
      let cityId = this.$store.state.city.id
      if(cityId === this.prevCity ) { return }
      this.isLoading = true
      const res = await this.$axios.get(`/api/cinemaList?cityId=${cityId}`)
      this.cinemas = res.data.data.cinemas
      this.isLoading = false
      this.prevCity = cityId
    },
 },
  activated() {
    this.fetch()
  },
  filters: {
    formatCard(key,args) {
      const card = [
        {key:'allowRefund', value:args[0]},
        {key:'endorse', value:args[1]},
        {key:'sell', value:args[2]},
        {key:'snack', value:args[3]},
      ]
      for(let v of card){
        if(v.key === key) {
          return v.value
        }
      }
      return ''
    }
  }
}
</script>

<style scoped>
#content .cinema_body{ flex:1; overflow:auto;}
.cinema_body ul{ padding:20px;}
.cinema_body li{  border-bottom:1px solid #e6e6e6; margin-bottom: 20px;}
.cinema_body div{ margin-bottom: 10px;}
.cinema_body .q{ font-size: 11px; color:#f03d37;}
.cinema_body .price{ font-size: 18px;}
.cinema_body .address{ font-size: 13px; color:#666;}
.cinema_body .address span:nth-of-type(2){ float:right; }
.cinema_body .card{ display: flex;}
.cinema_body .card div{ padding: 0 3px; height: 15px; line-height: 15px; border-radius: 2px; color: #f90; border: 1px solid #f90; font-size: 13px; margin-right: 5px;}
.cinema_body .card div.or{ color: #f90; border: 1px solid #f90;}
.cinema_body .card div.bl{ color: #589daf; border: 1px solid #589daf;}
</style>
